package gl.android.biyiqing.fragment;

import gl.uitls.DimenUtil;
import gl.view.pulltofresh.PullToRefreshView;
import gl.view.pulltofresh.PullToRefreshView.OnFooterRefreshListener;
import gl.view.pulltofresh.PullToRefreshView.OnHeaderRefreshListener;
import android.os.Bundle;
import android.view.View;
import android.widget.AbsListView;
import android.widget.ListView;

public class BaseListFragmet extends BaseFragment implements
		OnHeaderRefreshListener, OnFooterRefreshListener {
	public View onCreateView(android.view.LayoutInflater inflater,
			android.view.ViewGroup container,
			android.os.Bundle savedInstanceState) {
		return super.onCreateView(inflater, container, savedInstanceState);
	};
	protected boolean isRefreahHead = true;
	protected AbsListView getListView() {
		return (AbsListView) rootView.findViewById(android.R.id.list);
	}

	protected void setListViewDividerHeight(int hight) {
		((ListView) getListView()).setDividerHeight((int) DimenUtil
				.dp2px(hight));
	}
	
	PullToRefreshView mPullToRefreshView;

	@Override
	public void onViewCreated(View view, Bundle savedInstanceState) {
		super.onViewCreated(view, savedInstanceState);
//		mPullToRefreshView = (PullToRefreshView) view
//				.findViewById(R.id.fl_fresh_more);
		if (mPullToRefreshView!=null) {
			setPullListviewAble(false);
			mPullToRefreshView.setOnHeaderRefreshListener(this);
			mPullToRefreshView.setOnFooterRefreshListener(this);
		}
	}
	public void setPullListviewAble(boolean able){
		if (mPullToRefreshView!=null) {
			if (able) {
				mPullToRefreshView.unlock();
			}else{
				mPullToRefreshView.lock();
			}
		}
	}
	@Override
	public void onFooterRefresh(PullToRefreshView view) {
		view.onFooterRefreshComplete();

	}
	@Override
	protected void handComplete() {
		super.handComplete();
		if (mPullToRefreshView!=null) {
			mPullToRefreshView.onHeaderRefreshComplete();
		}
	}
	@Override
	protected void onAppendAbsListViewCommplete() {
		super.onAppendAbsListViewCommplete();
		if (mPullToRefreshView!=null) {
			mPullToRefreshView.onFooterRefreshComplete();
		}
	}
	@Override
	public void onHeaderRefresh(PullToRefreshView view) {
//		view.onHeaderRefreshComplete("");	
		isRefreahHead = true;
	}
	@Override
	public void handHeaderComplete() {
		if (isRefreahHead) {
			super.handHeaderComplete();
			if (mPullToRefreshView!=null) {
				mPullToRefreshView.onHeaderRefreshComplete("");
				isRefreahHead = false;
			}
		}
		
	}
}
